package com.lepu.app.fun.mother_circle.view;

import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.core.lib.widget.CircularImageView;
import com.eyzhs.app.R;
import com.lepu.app.fun.mother_circle.MotherCircleDetailActivity;
import com.lepu.app.fun.mother_circle.MotherTopicActivity;
import com.lepu.app.fun.mother_circle.bean.BeanMotherCircle;
import com.lepu.app.fun.mother_circle.bean.BeanMotherTopic;
import com.lepu.app.widget.ListViewForScrollview;

public class MotherTopicHeadView extends LinearLayout {

	private Context mContext;
	private int mTopicType = 1; // 1全部 2最新 3精华
	private BeanMotherCircle mMotherCircle;
	private ArrayList<BeanMotherTopic> mPubList;

	private RelativeLayout mTopicHeadLayout;
	private CircularImageView mTopicHeadAvatat;
	private TextView mTopicHeadTitle;
	private TextView mTopicHeadContent;
	private TextView mTopicHeadPeople;
	private TextView mTopicHeadTopic;
	
	private ListViewForScrollview mTopicHeadListView;

	public MotherTopicHeadView(Context context, int topicType,BeanMotherCircle motherCircle, ArrayList<BeanMotherTopic> pubList) {
		super(context);

		mContext = context;
		mTopicType = topicType;
		mMotherCircle = motherCircle;
		mPubList = pubList;

		LayoutInflater.from(mContext).inflate(R.layout.mother_topic_head_view,this, true);
		init();
	}

	public MotherTopicHeadView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	private void init() {
		mTopicHeadLayout = (RelativeLayout) findViewById(R.id.topic_head_layout);
		mTopicHeadAvatat = (CircularImageView) findViewById(R.id.topic_head_avatar);
		mTopicHeadTitle = (TextView) findViewById(R.id.topic_head_title);
		mTopicHeadContent = (TextView) findViewById(R.id.topic_head_content);
		mTopicHeadPeople = (TextView) findViewById(R.id.peopleCountTextView);
		mTopicHeadTopic = (TextView) findViewById(R.id.topicCountTextView);
		
		mTopicHeadListView = (ListViewForScrollview) findViewById(R.id.topic_head_listview);
		
		//全部显示置顶listview
		if(mTopicType == 1){
			if(mPubList != null && mPubList.size() > 0){
				mTopicHeadListView.setVisibility(View.GONE);
				//mTopicHeadListView.setAdapter(new AdapterMotherTopicHead(mContext, mPubList));
			}else{
				mTopicHeadListView.setVisibility(View.GONE);
			}
			
		}else{
			mTopicHeadListView.setVisibility(View.GONE);
		}
		
		mTopicHeadTitle.setText(mMotherCircle.cricleName);
		mTopicHeadContent.setText(mMotherCircle.cricleContent);
		mTopicHeadPeople.setText(mMotherCircle.criclePeopleCount+" 加入");
		mTopicHeadTopic.setText(mMotherCircle.cricleTopicCount+" 话题");
		
		UniversalImageLoadTool.disPlay(mMotherCircle.cricleAvatar, mTopicHeadAvatat, R.drawable.default_icon_small);
		
		mTopicHeadLayout.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(mContext, MotherCircleDetailActivity.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("motherCircle", mMotherCircle);
				intent.putExtras(bundle);
				((MotherTopicActivity)mContext).startActivity(intent,true);
			}
		});
	}


}
